#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Project : light-edit
@File : mysql_scan.py
@Author : Yj
@Time : 2025/9/9
@脚本说明 : MySQL 弱口令扫描模块
"""
import threading
import pymysql


def scan_mysql(host="127.0.0.1", port=3306, user="root", password="", connect_timeout=5):
    """尝试连接 MySQL 数据库，检测弱口令"""
    try:
        pymysql.connect(
            host=host,
            port=port,
            user=user,
            password=password,
            connect_timeout=connect_timeout,
            database="information_schema",
            charset="utf8",
            autocommit=True,
        )
        print(f"[+] {host}:{port} 存在MySQL数据库弱口令 -> {user}/{password}")
    except:
        pass


def mysql_run(host, port, users, passwords):
    """扫描指定主机的 MySQL 弱口令"""
    try:
        threads = []
        for user in users:
            for passwd in passwords:
                t = threading.Thread(target=scan_mysql, args=(host, port, user.strip(), passwd.strip()))
                t.start()
                threads.append(t)
        for t in threads:
            t.join()
    except:
        pass
